#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <msg_queue_peer.h>

struct msgbuf
{
    long mtype;
    char mdata[256];
};
struct msgbuf recvbuf;

void * recvb(void *b)
{
    while(1)
    {
        msg_queue_recv("b", &recvbuf, sizeof(recvbuf), 0, 0);
        printf("%s\n",recvbuf.mdata);
    }
    return NULL;
}

int main(int argc, char const *argv[])
{
    pthread_t t0;
    struct msgbuf sendbuf;
    sendbuf.mtype = 1;

    //创建线程
    if (pthread_create(&t0,NULL,recvb,NULL)<0)
    {
        puts("fail to create pthread t0");
        exit(1);
    }

    while(1)
    {
        char *p = fgets(sendbuf.mdata, 256, stdin);
        UNUSED(p);
        if (sendbuf.mdata[0] == 'a')
        {
            msg_queue_send("a", &sendbuf, sizeof(sendbuf), 0);
        }
        else if(sendbuf.mdata[0] == 'c')
        {
            msg_queue_send("c", &sendbuf, sizeof(sendbuf), 0);
        }
    }
    
    
    
    return 0;
}

